﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gtkj.CMS.Common
{
    public class DateTimeHelper
    {
        #region 构造函数
        public DateTimeHelper() { }
        #endregion

        #region 使用方法
        #region 进行时间转换
        /// <summary>
        /// 进行时间转换
        /// </summary>
        /// <param name="o_datetime">转换时间</param>
        /// <param name="o_type">时间类型(0:开始时间1:结束时间)</param>
        /// <returns>转换后的时间</returns>
        public DateTime ConvertDateTime(DateTime o_datetime, int o_type)
        {
            string t_date = o_datetime.ToShortDateString();

            if (o_type == 0)
            {
                return System.Convert.ToDateTime(t_date + " 00:00:00");
            }
            else
            {
                return System.Convert.ToDateTime(t_date + " 23:59:59");
            }
        }
        #endregion

        #region 时间格式化 YYYY-MM-DD HH:MM:SS
        public static DateTime DateTimeFormat(DateTime dt)
        {
            DateTime result;
            result = CutOffMillisecond(dt);
            return result;
        }
        #endregion
        #region 截断毫秒
        private static DateTime CutOffMillisecond(DateTime dt)
        {
            return new DateTime(dt.Ticks - (dt.Ticks % TimeSpan.TicksPerSecond), dt.Kind);
        }
        #endregion
        #endregion
    }
}